﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace TVLConversor
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private conversor conv = new conversor();

        private char[] digitos = new char[]{'0','1','2','3','4','5','6','7','8','9',',','\b'};

        private string[] unis = new string[] {"pulgadas","pies","yardas","millas","milímetros","centímetros","metros","kilómetros"};

        private string[] pesos = new string[] {"gramos", "kilogramos", "onza", "libra", "tonelada"};

        private void rellenacombounis(ComboBox c, string[] un)
        {
            c.Items.Clear();
            foreach (string u in un)
            {
                c.Items.Add(u);
            }
        }

        private bool CaracterCorrecto(char c)
        {
            // devolverá true si el carácter está en el array
            return (Array.IndexOf(digitos, c) != -1);
        }

        private void mensaje()
        {
            MessageBox.Show("No puedes escribir mas de una coma en un número.", "Error");
        }

        private void buttonClose_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void mostrartab1()
        {
            if (comboBoxunis1.Text != "" && comboBoxunis2.Text != "")
            {
                textBoxunis1.Visible = true;
                textBoxunis2.Visible = true;
                labelunison.Visible = true;
                labelunis2.Visible = true;

            }
        }

        private void mostrartab2()
        {
            if (comboBoxpeso1.Text != "" && comboBoxpeso2.Text != "")
            {
                textBoxpeso1.Visible = true;
                textBoxpeso2.Visible = true;
                labelpesoson.Visible = true;
                labelpeso.Visible = true;
            }
        }

        private void mostrartab3()
        {
            if (comboBoxtemp1.Text != "" && comboBoxtemp2.Text != "")
            {
                textBoxtemp1.Visible = true;
                textBoxtemp2.Visible = true;
                labeltempson.Visible = true;
                labeltemp.Visible = true;
            }
        }

        private void comboBoxunis1_SelectedIndexChanged(object sender, EventArgs e)
        {
            this.rellenacombounis(comboBoxunis2,unis);
            labelunison.Text = comboBoxunis1.Text + " son: ";
            comboBoxunis2.Items.Remove(comboBoxunis1.Text);
            comboBoxunis2.Items.Remove("pies");
            this.mostrartab1();
        }

        private void comboBoxunis2_SelectedIndexChanged(object sender, EventArgs e)
        {
            this.rellenacombounis(comboBoxunis1,unis);
            labelunis2.Text = comboBoxunis2.Text;
            comboBoxunis1.Items.Remove(comboBoxunis2.Text);
            this.mostrartab1();
        }

        private void comboBoxpeso1_SelectedIndexChanged(object sender, EventArgs e)
        {
            this.rellenacombounis(comboBoxpeso2, pesos);
            labelpesoson.Text = comboBoxpeso1.Text + " son: ";
            comboBoxpeso2.Items.Remove(comboBoxpeso1.Text);
            this.mostrartab2();
        }

        private void comboBoxpeso2_SelectedIndexChanged(object sender, EventArgs e)
        {
            this.rellenacombounis(comboBoxpeso1, pesos);
            labelpeso.Text = comboBoxpeso2.Text;
            comboBoxpeso1.Items.Remove(comboBoxpeso2.Text);
            this.mostrartab2();
        }

        private void comboBoxtemp1_SelectedIndexChanged(object sender, EventArgs e)
        {
            labeltempson.Text = comboBoxtemp1.Text + " son: ";
            comboBoxtemp2.Items.Remove(comboBoxtemp1.Text);
            this.mostrartab3();
        }

        private void comboBoxtemp2_SelectedIndexChanged(object sender, EventArgs e)
        {
            labeltemp.Text = comboBoxtemp2.Text;
            comboBoxtemp1.Items.Remove(comboBoxtemp2.Text);
            this.mostrartab3();
        }

        private void validador(object sender, KeyPressEventArgs e)
        {
            if (!CaracterCorrecto(e.KeyChar))
            {
                e.Handled = true;
            }
            base.OnKeyPress(e);
        }

        private void textBoxunis1_KeyPress(object sender, KeyPressEventArgs e)
        {
            this.validador(sender, e);
             
        }

        private void textBoxunis1_TextChanged(object sender, EventArgs e)
        {
            switch (comboBoxunis1.Text)
            {
                case "pulgadas":

                    switch (comboBoxunis2.Text)
                    {
                        case "milímetros":
                            if (textBoxunis1.Text != "")
                            {
                                try
                                {
                                    textBoxunis2.Text = conv.pulgTomm(Convert.ToDouble(textBoxunis1.Text)).ToString();
                                }
                                catch
                                {
                                    this.mensaje();
                                }
                            }
                            else
                            {
                                textBoxunis2.Text = "";
                            }
                                break;

                        case "centímetros":
                                if (textBoxunis1.Text != "")
                                {
                                    try
                                    {
                                        textBoxunis2.Text = conv.pulgTocm(Convert.ToDouble(textBoxunis1.Text)).ToString();
                                    }
                                    catch
                                    {
                                        this.mensaje();
                                    }
                                }
                                else
                                {
                                    textBoxunis2.Text = "";
                                }
                                break;

                        case "metros":
                                if (textBoxunis1.Text != "")
                                {
                                    try
                                    {
                                        textBoxunis2.Text = conv.pulgTom(Convert.ToDouble(textBoxunis1.Text)).ToString();
                                    }
                                    catch
                                    {
                                        this.mensaje();
                                    }
                                }
                                else
                                {
                                    textBoxunis2.Text = "";
                                }
                                break;

                        case "kilómetros":
                                if (textBoxunis1.Text != "")
                                {
                                    try
                                    {
                                        textBoxunis2.Text = conv.pulgTokm(Convert.ToDouble(textBoxunis1.Text)).ToString();
                                    }
                                    catch
                                    {
                                        this.mensaje();
                                    }
                                }
                                else
                                {
                                    textBoxunis2.Text = "";
                                }
                            break;

                        case "yardas":
                            if (textBoxunis1.Text != "")
                            {
                                try
                                {
                                    textBoxunis2.Text = conv.pulgToyarda(Convert.ToDouble(textBoxunis1.Text)).ToString();
                                }
                                catch
                                {
                                    this.mensaje();
                                }
                            }
                            else
                            {
                                textBoxunis2.Text = "";
                            }
                            break;

                        case "millas":
                            if (textBoxunis1.Text != "")
                            {
                                try
                                {
                                    textBoxunis2.Text = conv.pulgTomilla(Convert.ToDouble(textBoxunis1.Text)).ToString();
                                }
                                catch
                                {
                                    this.mensaje();
                                }
                            }
                            else
                            {
                                textBoxunis2.Text = "";
                            }
                            break;

                    }
                    break;
                case "pies":
                    switch (comboBoxunis2.Text)
                    {
                        case "centímetros":
                            if (textBoxunis1.Text != "")
                            {
                                try
                                {
                                    textBoxunis2.Text = conv.piesTocm(Convert.ToDouble(textBoxunis1.Text)).ToString();
                                }
                                catch
                                {
                                    this.mensaje();
                                }
                            }
                            else
                            {
                                textBoxunis2.Text = "";
                            }
                            break;

                        case "milímetros":
                            if (textBoxunis1.Text != "")
                            {
                                try
                                {
                                    textBoxunis2.Text = conv.piesTomm(Convert.ToDouble(textBoxunis1.Text)).ToString();
                                }
                                catch
                                {
                                    this.mensaje();
                                }
                            }
                            else
                            {
                                textBoxunis2.Text = "";
                            }
                            break;
                        case "metros":
                            if (textBoxunis1.Text != "")
                            {
                                try
                                {
                                    textBoxunis2.Text = conv.piesTom(Convert.ToDouble(textBoxunis1.Text)).ToString();
                                }
                                catch
                                {
                                    this.mensaje();
                                }
                            }
                            else
                            {
                                textBoxunis2.Text = "";
                            }
                            break;

                        case "kilómetros":
                            if (textBoxunis1.Text != "")
                            {
                                try
                                {
                                    textBoxunis2.Text = conv.piesTokm(Convert.ToDouble(textBoxunis1.Text)).ToString();
                                }
                                catch
                                {
                                    this.mensaje();
                                }
                            }
                            else
                            {
                                textBoxunis2.Text = "";
                            }
                            break;

                        case "millas":
                            if (textBoxunis1.Text != "")
                            {
                                try
                                {
                                    textBoxunis2.Text = conv.piesTomilla(Convert.ToDouble(textBoxunis1.Text)).ToString();
                                }
                                catch
                                {
                                    this.mensaje();
                                }
                            }
                            else
                            {
                                textBoxunis2.Text = "";
                            }
                            break;

                        case "yardas":
                            if (textBoxunis1.Text != "")
                            {
                                try
                                {
                                    textBoxunis2.Text = conv.piesToyarda(Convert.ToDouble(textBoxunis1.Text)).ToString();
                                }
                                catch
                                {
                                    this.mensaje();
                                }
                            }
                            else
                            {
                                textBoxunis2.Text = "";
                            }
                            break;

                        case "pulgadas":
                            if (textBoxunis1.Text != "")
                            {
                                try
                                {
                                    textBoxunis2.Text = conv.piesTopulg(Convert.ToDouble(textBoxunis1.Text)).ToString();
                                }
                                catch
                                {
                                    this.mensaje();
                                }
                            }
                            else
                            {
                                textBoxunis2.Text = "";
                            }
                            break;
                    }
                    break;
                    
                case "yardas":
                    switch (comboBoxunis2.Text)
                    {
                        case "metros":
                            if (textBoxunis1.Text != "")
                            {
                                try
                                {
                                    textBoxunis2.Text = conv.yardasTom(Convert.ToDouble(textBoxunis1.Text)).ToString();
                                }
                                catch
                                {
                                    this.mensaje();
                                }
                            }
                            else
                            {
                                textBoxunis2.Text = "";
                            }
                            break;

                        case "centímetros":
                            if (textBoxunis1.Text != "")
                            {
                                try
                                {
                                    textBoxunis2.Text = conv.yardasTocm(Convert.ToDouble(textBoxunis1.Text)).ToString();
                                }
                                catch
                                {
                                    this.mensaje();
                                }
                            }
                            else
                            {
                                textBoxunis2.Text = "";
                            }
                            break;

                        case "milímetros":
                            if (textBoxunis1.Text != "")
                            {
                                try
                                {
                                    textBoxunis2.Text = conv.yardasTomm(Convert.ToDouble(textBoxunis1.Text)).ToString();
                                }
                                catch
                                {
                                    this.mensaje();
                                }
                            }
                            else
                            {
                                textBoxunis2.Text = "";
                            }
                            break;

                        case "kilómetros":
                            if (textBoxunis1.Text != "")
                            {
                                try
                                {
                                    textBoxunis2.Text = conv.yardasTokm(Convert.ToDouble(textBoxunis1.Text)).ToString();
                                }
                                catch
                                {
                                    this.mensaje();
                                }
                            }
                            else
                            {
                                textBoxunis2.Text = "";
                            }
                            break;

                        case "pulgadas":
                            if (textBoxunis1.Text != "")
                            {
                                try
                                {
                                    textBoxunis2.Text = conv.yardasTopulg(Convert.ToDouble(textBoxunis1.Text)).ToString();
                                }
                                catch
                                {
                                    this.mensaje();
                                }
                            }
                            else
                            {
                                textBoxunis2.Text = "";
                            }
                            break;

                        case "millas":
                            if (textBoxunis1.Text != "")
                            {
                                try
                                {
                                    textBoxunis2.Text = conv.yardasTomilla(Convert.ToDouble(textBoxunis1.Text)).ToString();
                                }
                                catch
                                {
                                    this.mensaje();
                                }
                            }
                            else
                            {
                                textBoxunis2.Text = "";
                            }
                            break;
                    }
                    break;

                case "millas":
                    switch (comboBoxunis2.Text)
                    { 
                        case "kilómetros":
                            if (textBoxunis1.Text != "")
                            {
                                try
                                {
                                    textBoxunis2.Text = conv.millasTokm(Convert.ToDouble(textBoxunis1.Text)).ToString();
                                }
                                catch
                                {
                                    this.mensaje();
                                }
                            }
                            else
                            {
                                textBoxunis2.Text = "";
                            }
                            break;

                        case "metros":
                            if (textBoxunis1.Text != "")
                            {
                                try
                                {
                                    textBoxunis2.Text = conv.millasTom(Convert.ToDouble(textBoxunis1.Text)).ToString();
                                }
                                catch
                                {
                                    this.mensaje();
                                }
                            }
                            else
                            {
                                textBoxunis2.Text = "";
                            }
                            break;

                        case "centímetros":
                            if (textBoxunis1.Text != "")
                            {
                                try
                                {
                                    textBoxunis2.Text = conv.millasTocm(Convert.ToDouble(textBoxunis1.Text)).ToString();
                                }
                                catch
                                {
                                    this.mensaje();
                                }
                            }
                            else
                            {
                                textBoxunis2.Text = "";
                            }
                            break;

                        case "milímetros":
                            if (textBoxunis1.Text != "")
                            {
                                try
                                {
                                    textBoxunis2.Text = conv.millasTomm(Convert.ToDouble(textBoxunis1.Text)).ToString();
                                }
                                catch
                                {
                                    this.mensaje();
                                }
                            }
                            else
                            {
                                textBoxunis2.Text = "";
                            }
                            break;

                        case "pulgadas":
                            if (textBoxunis1.Text != "")
                            {
                                try
                                {
                                    textBoxunis2.Text = conv.millasTopulg(Convert.ToDouble(textBoxunis1.Text)).ToString();
                                }
                                catch
                                {
                                    this.mensaje();
                                }
                            }
                            else
                            {
                                textBoxunis2.Text = "";
                            }
                            break;

                        case "yardas":
                            if (textBoxunis1.Text != "")
                            {
                                try
                                {
                                    textBoxunis2.Text = conv.millasToyardas(Convert.ToDouble(textBoxunis1.Text)).ToString();
                                }
                                catch
                                {
                                    this.mensaje();
                                }
                            }
                            else
                            {
                                textBoxunis2.Text = "";
                            }
                            break;
                    }
                    break;

                case "milímetros":
                    switch (comboBoxunis2.Text)
                    {
                        case "pulgadas":
                            if (textBoxunis1.Text != "")
                            {
                                try
                                {
                                    textBoxunis2.Text = conv.mmTopulg(Convert.ToDouble(textBoxunis1.Text)).ToString();
                                }
                                catch
                                {
                                    this.mensaje();
                                }
                            }
                            else
                            {
                                textBoxunis2.Text = "";
                            }
                            break;

                        case "yardas":
                            if (textBoxunis1.Text != "")
                            {
                                try
                                {
                                    textBoxunis2.Text = conv.mmToyarda(Convert.ToDouble(textBoxunis1.Text)).ToString();
                                }
                                catch
                                {
                                    this.mensaje();
                                }
                            }
                            else
                            {
                                textBoxunis2.Text = "";
                            }
                            break;

                        case "centímetros":
                            if (textBoxunis1.Text != "")
                            {
                                try
                                {
                                    textBoxunis2.Text = conv.mmTocm(Convert.ToDouble(textBoxunis1.Text)).ToString();
                                }
                                catch
                                {
                                    this.mensaje();
                                }
                            }
                            else
                            {
                                textBoxunis2.Text = "";
                            }
                            break;

                        case "metros":
                            if (textBoxunis1.Text != "")
                            {
                                try
                                {
                                    textBoxunis2.Text = conv.mmTom(Convert.ToDouble(textBoxunis1.Text)).ToString();
                                }
                                catch
                                {
                                    this.mensaje();
                                }
                            }
                            else
                            {
                                textBoxunis2.Text = "";
                            }
                            break;

                        case "kilómetros":
                            if (textBoxunis1.Text != "")
                            {
                                try
                                {
                                    textBoxunis2.Text = conv.mmTokm(Convert.ToDouble(textBoxunis1.Text)).ToString();
                                }
                                catch
                                {
                                    this.mensaje();
                                }
                            }
                            else
                            {
                                textBoxunis2.Text = "";
                            }
                            break;

                        case "millas":
                            if (textBoxunis1.Text != "")
                            {
                                try
                                {
                                    textBoxunis2.Text = conv.mmTomilla(Convert.ToDouble(textBoxunis1.Text)).ToString();
                                }
                                catch
                                {
                                    this.mensaje();
                                }
                            }
                            else
                            {
                                textBoxunis2.Text = "";
                            }

                            break;
                    }
                    break;
            
                case "centímetros":
                    switch (comboBoxunis2.Text)
                    {
                        case "pulgadas":
                            if (textBoxunis1.Text != "")
                            {
                                try
                                {
                                    textBoxunis2.Text = conv.cmTopulg(Convert.ToDouble(textBoxunis1.Text)).ToString();
                                }
                                catch
                                {
                                    this.mensaje();
                                }
                            }
                            else
                            {
                                textBoxunis2.Text = "";
                            }
                            break;

                        case "yardas":
                            if (textBoxunis1.Text != "")
                            {
                                try
                                {
                                    textBoxunis2.Text = conv.cmToyarda(Convert.ToDouble(textBoxunis1.Text)).ToString();
                                }
                                catch
                                {
                                    this.mensaje();
                                }
                            }
                            else
                            {
                                textBoxunis2.Text = "";
                            }
                            break;

                        case "millas":
                            if (textBoxunis1.Text != "")
                            {
                                try
                                {
                                    textBoxunis2.Text = conv.cmTomilla(Convert.ToDouble(textBoxunis1.Text)).ToString();
                                }
                                catch
                                {
                                    this.mensaje();
                                }
                            }
                            else
                            {
                                textBoxunis2.Text = "";
                            }
                            break;

                        case "milímetros":
                            if (textBoxunis1.Text != "")
                            {
                                try
                                {
                                    textBoxunis2.Text = conv.cmTomm(Convert.ToDouble(textBoxunis1.Text)).ToString();
                                }
                                catch
                                {
                                    this.mensaje();
                                }
                            }
                            else
                            {
                                textBoxunis2.Text = "";
                            }
                            break;

                        case "metros":
                            if (textBoxunis1.Text != "")
                            {
                                try
                                {
                                    textBoxunis2.Text = conv.cmTom(Convert.ToDouble(textBoxunis1.Text)).ToString();
                                }
                                catch
                                {
                                    this.mensaje();
                                }
                            }
                            else
                            {
                                textBoxunis2.Text = "";
                            }
                            break;

                        case "kilómetros":
                            if (textBoxunis1.Text != "")
                            {
                                try
                                {
                                    textBoxunis2.Text = conv.cmTokm(Convert.ToDouble(textBoxunis1.Text)).ToString();
                                }
                                catch
                                {
                                    this.mensaje();
                                }
                            }
                            else
                            {
                                textBoxunis2.Text = "";
                            }
                            break;
                    }
                break;

                case "metros":
                    switch (comboBoxunis2.Text)
                    {
                        case "pulgadas":
                            if (textBoxunis1.Text != "")
                            {
                                try
                                {
                                    textBoxunis2.Text = conv.mTopulg(Convert.ToDouble(textBoxunis1.Text)).ToString();
                                }
                                catch
                                {
                                    this.mensaje();
                                }
                            }
                            else
                            {
                                textBoxunis2.Text = "";
                            }
                            break;

                        case "yardas":
                            if (textBoxunis1.Text != "")
                            {
                                try
                                {
                                    textBoxunis2.Text = conv.mToyarda(Convert.ToDouble(textBoxunis1.Text)).ToString();
                                }
                                catch
                                {
                                    this.mensaje();
                                }
                            }
                            else
                            {
                                textBoxunis2.Text = "";
                            }
                            break;

                        case "millas":
                            if (textBoxunis1.Text != "")
                            {
                                try
                                {
                                    textBoxunis2.Text = conv.mTomilla(Convert.ToDouble(textBoxunis1.Text)).ToString();
                                }
                                catch
                                {
                                    this.mensaje();
                                }
                            }
                            else
                            {
                                textBoxunis2.Text = "";
                            }
                            break;

                        case "milímetros":
                            if (textBoxunis1.Text != "")
                            {
                                try
                                {
                                    textBoxunis2.Text = conv.mTomm(Convert.ToDouble(textBoxunis1.Text)).ToString();
                                }
                                catch
                                {
                                    this.mensaje();
                                }
                            }
                            else
                            {
                                textBoxunis2.Text = "";
                            }
                            break;

                        case "centímetros":
                            if (textBoxunis1.Text != "")
                            {
                                try
                                {
                                    textBoxunis2.Text = conv.mTocm(Convert.ToDouble(textBoxunis1.Text)).ToString();
                                }
                                catch
                                {
                                    this.mensaje();
                                }
                            }
                            else
                            {
                                textBoxunis2.Text = "";
                            }
                            break;

                        case "kilómetros":
                            if (textBoxunis1.Text != "")
                            {
                                try
                                {
                                    textBoxunis2.Text = conv.mTokm(Convert.ToDouble(textBoxunis1.Text)).ToString();
                                }
                                catch
                                {
                                    this.mensaje();
                                }
                            }
                            else
                            {
                                textBoxunis2.Text = "";
                            }
                            break;
                    }
                    break;

                case "kilómetros":
                    switch (comboBoxunis2.Text)
                    { 
                        case "pulgadas":
                            if (textBoxunis1.Text != "")
                            {
                                try
                                {
                                    textBoxunis2.Text = conv.kmTopulg(Convert.ToDouble(textBoxunis1.Text)).ToString();
                                }
                                catch
                                {
                                    this.mensaje();
                                }
                            }
                            else
                            {
                                textBoxunis2.Text = "";
                            }
                            break;

                        case "yardas":
                            if (textBoxunis1.Text != "")
                            {
                                try
                                {
                                    textBoxunis2.Text = conv.kmToyarda(Convert.ToDouble(textBoxunis1.Text)).ToString();
                                }
                                catch
                                {
                                    this.mensaje();
                                }
                            }
                            else
                            {
                                textBoxunis2.Text = "";
                            }
                            break;

                        case "millas":
                            if (textBoxunis1.Text != "")
                            {
                                try
                                {
                                    textBoxunis2.Text = conv.kmTomilla(Convert.ToDouble(textBoxunis1.Text)).ToString();
                                }
                                catch
                                {
                                    this.mensaje();
                                }
                            }
                            else
                            {
                                textBoxunis2.Text = "";
                            }
                            break;

                        case "milímetros":
                            if (textBoxunis1.Text != "")
                            {
                                try
                                {
                                    textBoxunis2.Text = conv.kmTomm(Convert.ToDouble(textBoxunis1.Text)).ToString();
                                }
                                catch
                                {
                                    this.mensaje();
                                }
                            }
                            else
                            {
                                textBoxunis2.Text = "";
                            }
                            break;

                        case "centímetros":
                            if (textBoxunis1.Text != "")
                            {
                                try
                                {
                                    textBoxunis2.Text = conv.kmTocm(Convert.ToDouble(textBoxunis1.Text)).ToString();
                                }
                                catch
                                {
                                    this.mensaje();
                                }
                            }
                            else
                            {
                                textBoxunis2.Text = "";
                            }
                            break;

                        case "metros":
                            if (textBoxunis1.Text != "")
                            {
                                try
                                {
                                    textBoxunis2.Text = conv.kmTom(Convert.ToDouble(textBoxunis1.Text)).ToString();
                                }
                                catch
                                {
                                    this.mensaje();
                                }
                            }
                            else
                            {
                                textBoxunis2.Text = "";
                            }
                            break;
                    }
                    break;
            }
            
        }

        private void textBoxpeso1_TextChanged(object sender, EventArgs e)
        {
            switch (comboBoxpeso1.Text)
            { 
                case"gramos":
                    switch (comboBoxpeso2.Text)
                    {
                        case"kilogramos":
                            if (textBoxpeso1.Text != "")
                            {
                                try
                                {
                                    textBoxpeso2.Text = conv.gTokg(Convert.ToDouble(textBoxpeso1.Text)).ToString();
                                }
                                catch
                                {
                                    this.mensaje();
                                }
                            }
                            else
                            {
                                textBoxpeso2.Text = "";
                            }
                            break;

                        case "onza":
                            if (textBoxpeso1.Text != "")
                            {
                                try
                                {
                                    textBoxpeso2.Text = conv.gToonza(Convert.ToDouble(textBoxpeso1.Text)).ToString();
                                }
                                catch
                                {
                                    this.mensaje();
                                }
                            }
                            else
                            {
                                textBoxpeso2.Text = "";
                            }
                            break;

                        case "libra":
                            if (textBoxpeso1.Text != "")
                            {
                                try
                                {
                                    textBoxpeso2.Text = conv.kgTolibra(Convert.ToDouble(textBoxpeso1.Text)).ToString();
                                }
                                catch
                                {
                                    this.mensaje();
                                }
                            }
                            else
                            {
                                textBoxpeso2.Text = "";
                            }
                            break;

                        case"tonelada":
                            if (textBoxpeso1.Text != "")
                            {
                                try
                                {
                                    textBoxpeso2.Text = conv.gToton(Convert.ToDouble(textBoxpeso1.Text)).ToString();
                                }
                                catch
                                {
                                    this.mensaje();
                                }
                            }
                            else
                            {
                                textBoxpeso2.Text = "";
                            }
                            break;
                    }
                    break;
                case "kilogramos":
                    switch (comboBoxpeso2.Text)
                    {
                        case "gramos":
                            if (textBoxpeso1.Text != "")
                            {
                                try
                                {
                                    textBoxpeso2.Text = conv.kgTog(Convert.ToDouble(textBoxpeso1.Text)).ToString();
                                }
                                catch
                                {
                                    this.mensaje();
                                }
                            }
                            else
                            {
                                textBoxpeso2.Text = "";
                            }
                            break;

                        case "onza":
                            if (textBoxpeso1.Text != "")
                            {
                                try
                                {
                                    textBoxpeso2.Text = conv.kgToonza(Convert.ToDouble(textBoxpeso1.Text)).ToString();
                                }
                                catch
                                {
                                    this.mensaje();
                                }
                            }
                            else
                            {
                                textBoxpeso2.Text = "";
                            }
                            break;

                        case "libra":
                            if (textBoxpeso1.Text != "")
                            {
                                try
                                {
                                    textBoxpeso2.Text = conv.kgTolibra(Convert.ToDouble(textBoxpeso1.Text)).ToString();
                                }
                                catch
                                {
                                    this.mensaje();
                                }
                            }
                            else
                            {
                                textBoxpeso2.Text = "";
                            }
                            break;

                        case "tonelada":
                            if (textBoxpeso1.Text != "")
                            {
                                try
                                {
                                    textBoxpeso2.Text = conv.kgToton(Convert.ToDouble(textBoxpeso1.Text)).ToString();
                                }
                                catch
                                {
                                    this.mensaje();
                                }
                            }
                            else
                            {
                                textBoxpeso2.Text = "";
                            }
                            break;
                    }

                    break;

                case "onza":
                    switch (comboBoxpeso2.Text)
                    {
                        case "gramos":
                            if (textBoxpeso1.Text != "")
                            {
                                try
                                {
                                    textBoxpeso2.Text = conv.onzaTog(Convert.ToDouble(textBoxpeso1.Text)).ToString();
                                }
                                catch
                                {
                                    this.mensaje();
                                }
                            }
                            else
                            {
                                textBoxpeso2.Text = "";
                            }
                            break;

                        case "kilogramos":
                            if (textBoxpeso1.Text != "")
                            {
                                try
                                {
                                    textBoxpeso2.Text = conv.onzaTokg(Convert.ToDouble(textBoxpeso1.Text)).ToString();
                                }
                                catch
                                {
                                    this.mensaje();
                                }
                            }
                            else
                            {
                                textBoxpeso2.Text = "";
                            }
                            break;

                        case "libra":
                            if (textBoxpeso1.Text != "")
                            {
                                try
                                {
                                    textBoxpeso2.Text = conv.onzaTolibra(Convert.ToDouble(textBoxpeso1.Text)).ToString();
                                }
                                catch
                                {
                                    this.mensaje();
                                }
                            }
                            else
                            {
                                textBoxpeso2.Text = "";
                            }
                            break;

                        case "tonelada":
                            if (textBoxpeso1.Text != "")
                            {
                                try
                                {
                                    textBoxpeso2.Text = conv.onzaToton(Convert.ToDouble(textBoxpeso1.Text)).ToString();
                                }
                                catch
                                {
                                    this.mensaje();
                                }
                            }
                            else
                            {
                                textBoxpeso2.Text = "";
                            }
                            break;
                    }
                    break;
                    
                case "libra":
                        switch(comboBoxpeso2.Text)
                        {
                            case "gramos":
                                if (textBoxpeso1.Text != "")
                                {
                                    try
                                    {
                                        textBoxpeso2.Text = conv.libraTog(Convert.ToDouble(textBoxpeso1.Text)).ToString();
                                    }
                                    catch
                                    {
                                        this.mensaje();
                                    }
                                }
                                else
                                {
                                    textBoxpeso2.Text = "";
                                }
                                break;

                            case "kilogramos":
                                if (textBoxpeso1.Text != "")
                                {
                                    try
                                    {
                                        textBoxpeso2.Text = conv.libraTokg(Convert.ToDouble(textBoxpeso1.Text)).ToString();
                                    }
                                    catch
                                    {
                                        this.mensaje();
                                    }
                                }
                                else
                                {
                                    textBoxpeso2.Text = "";
                                }
                                break;

                            case "onza":
                                if (textBoxpeso1.Text != "")
                                {
                                    try
                                    {
                                        textBoxpeso2.Text = conv.libraToonz(Convert.ToDouble(textBoxpeso1.Text)).ToString();
                                    }
                                    catch
                                    {
                                        this.mensaje();
                                    }
                                }
                                else
                                {
                                    textBoxpeso2.Text = "";
                                }
                                break;

                            case "tonelada":
                                if (textBoxpeso1.Text != "")
                                {
                                    try
                                    {
                                        textBoxpeso2.Text = conv.libraToton(Convert.ToDouble(textBoxpeso1.Text)).ToString();
                                    }
                                    catch
                                    {
                                        this.mensaje();
                                    }
                                }
                                else
                                {
                                    textBoxpeso2.Text = "";
                                }
                                break;
                        }
                    break;

                case "tonelada":
                    switch (comboBoxpeso2.Text)
                    {
                        case "gramos":
                            if (textBoxpeso1.Text != "")
                            {
                                try
                                {
                                    textBoxpeso2.Text = conv.tonTog(Convert.ToDouble(textBoxpeso1.Text)).ToString();
                                }
                                catch
                                {
                                    this.mensaje();
                                }
                            }
                            else
                            {
                                textBoxpeso2.Text = "";
                            }
                            break;

                        case "kilogramos":
                            if (textBoxpeso1.Text != "")
                            {
                                try
                                {
                                    textBoxpeso2.Text = conv.tonTokg(Convert.ToDouble(textBoxpeso1.Text)).ToString();
                                }
                                catch
                                {
                                    this.mensaje();
                                }
                            }
                            else
                            {
                                textBoxpeso2.Text = "";
                            }
                            break;

                        case "onza":
                            if (textBoxpeso1.Text != "")
                            {
                                try
                                {
                                    textBoxpeso2.Text = conv.tonToonza(Convert.ToDouble(textBoxpeso1.Text)).ToString();
                                }
                                catch
                                {
                                    this.mensaje();
                                }
                            }
                            else
                            {
                                textBoxpeso2.Text = "";
                            }
                            break;

                        case "libra":
                            if (textBoxpeso1.Text != "")
                            {
                                try
                                {
                                    textBoxpeso2.Text = conv.tonTolibra(Convert.ToDouble(textBoxpeso1.Text)).ToString();
                                }
                                catch
                                {
                                    this.mensaje();
                                }
                            }
                            else
                            {
                                textBoxpeso2.Text = "";
                            }
                            break;
                    }
                    break;
            }
        }

        private void textBoxpeso1_KeyPress(object sender, KeyPressEventArgs e)
        {
            this.validador(sender, e);
        }

        private void textBoxtemp1_KeyPress(object sender, KeyPressEventArgs e)
        {
            this.validador(sender, e);
        }

        private void textBoxtemp1_TextChanged(object sender, EventArgs e)
        {
            if(comboBoxtemp1.Text == "Celsius" && comboBoxtemp2.Text == "Farenheit")
            {
                if (textBoxtemp1.Text != "")
                {
                    try
                    {
                        textBoxtemp2.Text = conv.celsToFaren(Convert.ToDouble(textBoxtemp1.Text)).ToString();
                    }
                    catch
                    {
                        this.mensaje();
                    }
                }
                else
                {
                    textBoxtemp2.Text = "";
                }
            }

            if (comboBoxtemp1.Text == "Farenheit" && comboBoxtemp2.Text == "Celsius")
            {
                if (textBoxtemp1.Text != "")
                {
                    try
                    {
                        textBoxtemp2.Text = conv.farenToCels(Convert.ToDouble(textBoxtemp1.Text)).ToString();
                    }
                    catch
                    {
                        this.mensaje();
                    }
                }
                else
                {
                    textBoxtemp2.Text = "";
                }
            }
            
        }
    }
}
